#ifndef EMBEDDINGMANAGER_H
#define EMBEDDINGMANAGER_H

#include <QObject>
#include <QDebug>
#include <QWaitCondition>
#include <QMutex>
#include <QStringList>
#include <QVector>
#include <coreai/embedding/embedding.h>
#include <vectordatabase.h>
#include <QFile>
#include <QTextStream>
#include <algorithm>

class EmbeddingManager : public QObject
{
    Q_OBJECT

public:
    explicit EmbeddingManager(QObject *parent = nullptr);
    bool initialize();

public slots:
    void processDocuments(const QStringList &filePaths,int maxChunkSize, int minChunkSize);
    QStringList queryRAG(const QString &question, int topK);
    void resetVectorDatabase();

private:
    TextEmbeddingSession *m_session;
    VectorDatabase *m_vectorDB;
    QMutex m_mutex;

    QVector<float> getEmbeddingSync(const QString &text);
    QStringList readTextFile(const QString &filePath,int maxChunkSize, int minChunkSize);
    QStringList splitTextIntoChunks(const QString &text, int maxChunkSize, int minChunkSize);
    bool isCompleteSentence(const QString &text);
};

#endif // EMBEDDINGMANAGER_H
